<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.conn.RecordSet" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="bb" class="weaver.general.BaseBean"/>
<%
    /*
     *@Description: 采购决策流程带主表信息
     *@Param: [request, response]
     *@return: void
     *@Author: Dusongsong
     *@Date: 2021/1/13
     */

    String cglx1 = Util.null2String( request.getParameter( "cglx1" ) );//采购类型
    String cglx = Util.null2String( request.getParameter( "cglx" ) );//项目名称
    bb.writeLog("cglx1="+cglx1);
    bb.writeLog("cglx="+cglx);
    JSONObject jsonData = new JSONObject();
    String zblx_table = bb.getPropValue("srm_wf_table","zblx_table");
    bb.writeLog("zblx_table="+zblx_table);
    String data = "";
    switch (cglx1) {
        case "0":
            String wlmcNames = "";
            String sql = "select t1.wlmc from  "+zblx_table+"_dt1 t1 left join "+zblx_table+" t on t.id=t1.mainid where t.cglxing =? and t.id=?";
            rs.executeQuery(sql,cglx1,cglx);
            while (rs.next()){
            String wlmc =Util.null2String(rs.getString(1));//物料品类
            String wlmcName = getWlplName(wlmc);
                wlmcNames += "".equals( wlmcNames ) ? wlmcName : ";" + wlmcName;
            }
            data =  wlmcNames ;
            break;//物料采购需求池
        case "1":
            String mc2bds = "";
            String sql1 = "select t1.fbmc,t1.fbbd from  "+zblx_table+"_dt2 t1 left join "+zblx_table+" t on t.id=t1.mainid where t.cglxing =? and t.id=?";
            rs.executeQuery(sql1,cglx1,cglx);
            while (rs.next()){
                String fbmc =Util.null2String(rs.getString("fbmc"));//分包名称
                String fbbd =Util.null2String(rs.getString("fbbd"));//分包表段
                String fbmcName = getFbmcName(fbmc);
                String fbbdName = getFbbdName(fbbd);
                String mc2bd = fbmcName+"-"+fbbdName;
                mc2bds += "".equals( mc2bds ) ? mc2bd : ";" + mc2bd;
            }
            data =  mc2bds ;
            break;//工程采购需求池
        case "2":
            String zkxqlxs = "";
            String sql2 = "select t1.xqlx from  "+zblx_table+"_dt3 t1 left join "+zblx_table+" t on t.id=t1.mainid where t.cglxing =? and t.id=?";
            rs.executeQuery(sql2,cglx1,cglx);
            while (rs.next()){
                String xqlx =Util.null2String(rs.getString("xqlx"));//需求内容
                zkxqlxs += "".equals( zkxqlxs ) ? xqlx : ";" + xqlx;
            }
            data =  zkxqlxs ;
            break;//租赁采购需求池
        case "3":
            String ysxqlxs = "";
            String sql3 = "select t1.xqlx from  "+zblx_table+"_dt7 t1 left join "+zblx_table+" t on t.id=t1.mainid where t.cglxing =? and t.id=?";
            rs.executeQuery(sql3,cglx1,cglx);
            while (rs.next()){
                String xqlx =Util.null2String(rs.getString("xqlx"));//需求内容
                ysxqlxs += "".equals( ysxqlxs ) ? xqlx : ";" + xqlx;
            }
            data =  ysxqlxs ;
            break;//运输采购需求池
        case "4":
            String fwxqlxs = "";
            String sql4 = "select t1.xqlx from  "+zblx_table+"_dt8 t1 left join "+zblx_table+" t on t.id=t1.mainid where t.cglxing =? and t.id=?";
            rs.executeQuery(sql4,cglx1,cglx);
            while (rs.next()){
                String xqlx =Util.null2String(rs.getString("xqlx"));//需求内容
                fwxqlxs += "".equals( fwxqlxs ) ? xqlx : ";" + xqlx;
            }
            data =  fwxqlxs ;
            break;//服务采购需求池
    }
    jsonData.put( "datas", data );
    out.print( jsonData.toJSONString() );
    bb.writeLog( "getCgjcData_Ajax=" + jsonData.toJSONString() );
%>
<%!
    //获取物料品类名称
 public static String getWlplName(String id){
     RecordSet rs = new RecordSet();
     rs.executeQuery("select wlpl from uf_wlpl where id ='"+id+"'");
     rs.next();
     String wlpl = Util.null2String(rs.getString( "wlpl"));//物料品类
     return wlpl;
 }
    //获取分包名称名称
    public static String getFbmcName(String id){
        RecordSet rs = new RecordSet();
        rs.executeQuery("select fbmc from uf_2 where id ='"+id+"'");
        rs.next();
        String fbmc = Util.null2String(rs.getString( "fbmc"));//分包名称
        return fbmc;
    }
    //获取分包标段名称
    public static String getFbbdName(String id){
        RecordSet rs = new RecordSet();
        rs.executeQuery("select fbbd from uf_1 where id ='"+id+"'");
        rs.next();
        String fbbd = Util.null2String(rs.getString( "fbbd"));//分包标段
        return fbbd;
    }
%>

